#include "DirectorLoader.h"
#include "math.h"

/****************************************************************/
// Get value for positive log graph equation, , y = ke^x + c
float DirectorLoader::getPosLogVarK(float pointY1, float pointY2, float pointX1, float pointX2)
{
	float denominator = exp(pointX2)-exp(pointX1);
	if( denominator == 0.0 ) return 0.0; // cannot divide by 0
	return ( pointY2-pointY1 ) / denominator;
}
float DirectorLoader::getPosLogVarC(float varK, float pointY1, float pointX1)
{
	return pointY1 - varK * exp(pointX1);
}
float DirectorLoader::getPosLogXValue(float varK, float varC, float varY)
{
	if( varK == 0 ) return 0.0;
	float innerProduct = (varY-varC) / varK;
	if( innerProduct <= 0 ) return 0.0; // cannot log a negative value
	return  ( log ( innerProduct ) ); // x = log ( (y-c)/k )
}
float DirectorLoader::getPosLogYValue(float varK, float varC, float varY)
{
	return  varK * exp(varY) + varC; // y = 1.29e^x + 0.52
}

/****************************************************************/
// Get value for negative log graph equation, , y = ke^-x + c
float DirectorLoader::getNegLogVarK(float pointY1, float pointY2, float pointX1, float pointX2)
{
	float denominator = (1.0/exp(pointX2)) - (1.0/exp(pointX1));
	if( denominator == 0.0 ) return 0.0; // cannot divide by 0
	return ( pointY2-pointY1 ) / denominator;
}
float DirectorLoader::getNegLogVarC(float varK, float pointY1, float pointX1)
{
	float denominator = exp(pointX1);
	if( denominator == 0.0 ) return 0.0; // cannot divide by 0
	return pointY1 - varK / denominator; // k*1.0/e^x = k/e^x
}
float DirectorLoader::getNegLogValue(float varK, float varC, float varY)
{
	if( varK == 0 ) return 0.0;
	float innerProduct = (varY-varC) / varK;
	if( innerProduct <= 0 ) return 0.0; // cannot log a negative value
	return  -log ( innerProduct ); // x = - log ( (y-c)/k )
}

/****************************************************************/
// Get value for positive straight line graph, y = kx + c
float DirectorLoader::getPosLineVarK(float pointY1, float pointY2, float pointX1, float pointX2)
{
	float denominator = pointX2-pointX1;
	if( denominator == 0.0 ) return 0.0; // cannot divide by 0
	return ( pointY2-pointY1 ) / denominator;
}
float DirectorLoader::getPosLineVarC(float varK, float pointY1, float pointX1)
{
	return pointY1 - varK * pointX1;
}
float DirectorLoader::getPosLineValue(float varK, float varC, float varY)
{
	if( varK == 0 ) return 0.0; // cannot divide by 0
	return  ( ( varY - varC ) / varK ); // x = ( y-c ) / k
}

/****************************************************************/
// Get value for positive straight line graph, y = -kx + c
float DirectorLoader::getNegLineVarK(float pointY1, float pointY2, float pointX1, float pointX2)
{
	float denominator = pointX2-pointX1;
	if( denominator == 0.0 ) return 0.0; // cannot divide by 0
	return ( pointY1-pointY2 ) / denominator;
}
float DirectorLoader::getNegLineVarC(float varK, float pointY1, float pointX1)
{
	return pointY1 + varK * pointX1;
}
float DirectorLoader::getNegLineValue(float varK, float varC, float varY)
{
	if( varK == 0 ) return 0.0; // cannot divide by 0
	return  ( ( varC - varY ) / varK ); // x = ( c-y ) / k
}
